package com.guguskins.back.controller;


import com.guguskins.back.common.annotation.Authorized;
import com.guguskins.back.entity.GuFeedback;
import com.guguskins.back.entity.vo.PageVo;
import com.guguskins.back.entity.vo.ResultVo;
import com.guguskins.back.service.GuFeedbackService;
import com.guguskins.back.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 问题反馈表 前端控制器
 * </p>
 *
 * @author mybatis-plus
 * @since 2021-05-10
 */
@RestController
@RequestMapping("/feedback")
public class GuFeedbackController {

    @Autowired
    private GuFeedbackService feedbackService;

    @GetMapping("/back/page")
    public ResultVo backPage(@RequestParam(value = "p", required = false, defaultValue = "1") int p,
                             @RequestParam(value = "size", required = false, defaultValue = "10") int size,
                             @RequestParam(value = "status", required = false, defaultValue = "-1") int status,
                             @RequestParam(value = "searchKey", required = false, defaultValue = "") String searchKey) {
        PageVo<GuFeedback> feedbackPageVo = feedbackService.backPage(p, size, status, searchKey);
        return ResultVo.success(feedbackPageVo);
    }

    @PostMapping("/addition")
    @Authorized
    public ResultVo addition(@RequestHeader("token") String token,
                             @RequestBody GuFeedback feedback) {
        Long userId = JwtUtil.verifyToken(token).get("userId", Long.class);
        feedback.setFeedbackUserId(userId);
        if (feedbackService.addition(feedback)) {
            return ResultVo.success("提交成功");
        }
        return ResultVo.fail("提交失败");
    }

    /**
     * 问题反馈的列表

//    @GetMapping("back/list")
//    public ResultVo getList() {
//        return ResultVo.success(feedbackService.list());
//    }
     */




    /**
     * 问题反馈的修改
     */
    @PostMapping("/back/update")
    public ResultVo feedBackUpdate(@RequestBody  GuFeedback guFeedback) {
        feedbackService.updateById(guFeedback);
        return ResultVo.success("修改成功");
    }


}
